package com.mryan.aop_mylog.controller;

import com.mryan.aop_mylog.constant.UserConstant;
import com.mryan.aop_mylog.dao.UserServiceImpl;
import com.mryan.aop_mylog.pojo.User;
import com.mryan.aop_mylog.utils.MyLog;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.websocket.server.PathParam;
import java.util.List;
import java.util.logging.Logger;

/**
 * @description：
 * @Author MRyan
 * @Date 2021/1/6 17:01
 * @Version 1.0
 */

@RestController
public class UserController {

    private static Logger logger = Logger.getLogger("Main.class");

    @Autowired
    private UserServiceImpl userService;

    @MyLog(myModul = "用户管理-用户查询", myType = UserConstant.QUERY, myrDesc = "查询用户信息")
    @RequestMapping("/index/{age}")
    public List<User> queryUserList(@PathVariable("age") Integer age) {
        List<User> userList = userService.getUserList(age);
        for (User user : userList) {
            logger.info(user.getId() + " " + user.getName() + " " + user.getPwd());
        }
        return userList;
    }


    @MyLog(myModul = "用户管理-用户查询2", myType = UserConstant.QUERY, myrDesc = "查询用户信息2")
    @RequestMapping("/index2/{age}")
    public List<User> queryUserList2(@PathVariable("age") Integer age) {
        List<User> userList = userService.getUserList(age);
        for (User user : userList) {
            logger.info(user.getId() + " " + user.getName() + " " + user.getPwd());
        }
        return userList;
    }
}
